{% extends "layouts/base.volt" %}

{% block title %}{{ get_title() }}{% endblock %}
{% block content %}
{{ partial("layouts/navbar", ['currentPage': 'admin']) }}
<!-- for beautify -->
{{ partial("layouts/subnavbar")}}
<div class="main">
	
	<div class="main-inner">

	    <div class="container">
	
	      <div class="row">
	      	
	      	<div class="span12">      		
	      		
	      		<div class="widget ">
	      			
	      			<div class="widget-header">
	      				<i class="icon-zoom-in"></i>
	      				<h3>测试题目 | <a href="#modalAdd" data-toggle="modal">添加</a></h3>

	  				</div> <!-- /widget-header -->
					
					<div class="widget-content">
						<table class="table table-striped">
						    <thead>
						        <tr>
						          	<th>#</th>
						          	<th>标题</th>
						          	<th>问题</th>
						          	<th>操作</th>
						        </tr>
						    </thead>
						    <tbody>
						    	{% for test in tests %}
						    	    <tr>
							    		<th scope="row">{{ test.getId() }}</th>
							    		<td>{{ test.getTitle() }}</td>
							    		<td>{{ test.getQuestion() }}</td>
	          							<td><a href="#modal{{ test.getId() }}" data-toggle="modal">修改</a> | <a href="#" onclick="delTest({{ test.getId() }})">删除</a></td>
          							</tr>
          							<form id="edit-profile-{{ test.getId() }}" class="form-horizontal" action="#" method="post">
	          							<!-- Modal -->
										<div id="modal{{ test.getId() }}" class="modal hide fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												<h3 id="myModalLabel">修改题目</h3>
											</div>
											<div class="modal-body">
												
													<fieldset>
														<input type="text" class="span5" name="id" value="{{ test.getId() }}" style="display:none">
														<div class="control-group">											
															<label class="control-label" for="title">标题</label>
															<div class="controls">
																<input type="text" class="span5" name="title" value="{{ test.getTitle() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="question">问题</label>
															<div class="controls">
																<textarea class="span5" name="question" rows="3">{{ test.getQuestion() }}</textarea>
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_1">选项1</label>
															<div class="controls">
																<input type="text" class="span5" name="option_1" value="{{ test.getOption_1() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_2">选项2</label>
															<div class="controls">
																<input type="text" class="span5" name="option_2" value="{{ test.getOption_2() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_3">选项3</label>
															<div class="controls">
																<input type="text" class="span5" name="option_3" value="{{ test.getOption_3() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_4">选项4</label>
															<div class="controls">
																<input type="text" class="span5" name="option_4" value="{{ test.getOption_4() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">
															{% set ids = [1,2,3,4] %}										
															<label class="control-label" for="select">正确答案</label>
																{% for id in ids %}
																<label class="radio inline">
																	{% if id == test.getCorrect_answer() %}
	                                              					<input type="radio" name="select" value="{{ id }}" checked> {{ id }}
	                                              					{% else %}
	                                              					<input type="radio" name="select" value="{{ id }}"> {{ id }}
	                                              					{% endif %}
	                                            				</label>
	                                            				{% endfor %}
				                                            <div class="controls">

				                                            </div>	<!-- /controls -->			
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="score">得分</label>
															<div class="controls">
																<input type="text" class="span5" name="score" value="{{ test.getScore() }}">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
													</fieldset>
												
											</div>
											<div class="modal-footer">
												<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												<button  class="btn btn-primary" type="submit">保存</button>
											</div>
										</div>
									</form>
          						{% endfor %}
          							<form id="edit-profile-add" class="form-horizontal" action="#" method="post">
	          							<!-- Modal -->
										<div id="modalAdd" class="modal hide fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
												<h3 id="myModalLabel">添加题目</h3>
											</div>
											<div class="modal-body">
												
													<fieldset>
														<!-- default -->
														<input type="text" class="span5" name="testid" value="1" style="display:none">
														<input type="text" class="span5" name="type" value="1" style="display:none">

														<div class="control-group">											
															<label class="control-label" for="title">标题</label>
															<div class="controls">
																<input type="text" class="span5" name="title" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="question">问题</label>
															<div class="controls">
																<textarea class="span5" name="question" rows="3"></textarea>
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_1">选项1</label>
															<div class="controls">
																<input type="text" class="span5" name="option_1" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_2">选项2</label>
															<div class="controls">
																<input type="text" class="span5" name="option_2" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_3">选项3</label>
															<div class="controls">
																<input type="text" class="span5" name="option_3" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="option_4">选项4</label>
															<div class="controls">
																<input type="text" class="span5" name="option_4" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
														<div class="control-group">
															{% set ids = [1,2,3,4] %}										
															<label class="control-label" for="select">正确答案</label>
																{% for id in ids %}
																<label class="radio inline">
	                                              					<input type="radio" name="select" value="{{ id }}"> {{ id }}
	                                            				</label>
	                                            				{% endfor %}
				                                            <div class="controls">

				                                            </div>	<!-- /controls -->			
														</div> <!-- /control-group -->
														<div class="control-group">											
															<label class="control-label" for="score">得分</label>
															<div class="controls">
																<input type="text" class="span5" name="score" value="">
															</div> <!-- /controls -->				
														</div> <!-- /control-group -->
													</fieldset>
												
											</div>
											<div class="modal-footer">
												<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
												<button  class="btn btn-primary" type="submit">保存</button>
											</div>
										</div>
									</form>
						    </tbody>
						</table>
						
					</div> <!-- /widget-content -->
						
				</div> <!-- /widget -->
	      		
		    </div> <!-- /span8 -->
	      	
	      	
	      	
	      	
	      </div> <!-- /row -->
	
	    </div> <!-- /container -->
	    
	</div> <!-- /main-inner -->
    
</div> <!-- /main -->




{% endblock %}

{% block js %}
<script>
function delTest(id){
	$.get("/admin/delTest",{ id: id }, function(data){
		if(data == "success"){
		    alert("删除成功");
		    window.location.reload();
		}else{
		    alert("删除失败");
		}
	});
}
$(document).ready(function(){
  	$('form').submit(function() {
  		if($(this).attr("id") != "edit-profile-add"){
			$.post("/admin/saveChange",$(this).serialize(),function(data,status){
		      if(data == "success"){
		        alert("修改成功");
		        window.location.reload();
		      }else{
		      	alert("修改失败");
		      }
		    });
		}else{
			$.post("/admin/saveAdd",$(this).serialize(),function(data,status){
		      if(data == "success"){
		        alert("添加成功");
		        window.location.reload();
		      }else{
		      	alert("添加失败");
		      }
		    });
		}
	    return false;
	});
});
</script>
{% endblock %}